<?php
namespace app\api\controller\ledger;

use app\api\controller\Base;
use app\api\controller\Baseuser;


use app\common\model\account\AccountCreate;
use app\common\model\company\Company;
use think\facade\Request;

class Create extends Base
{
    // 创建产生台账
    public function createLedger()
    {
        $params =  Request::instance()->param();
        $result = $this->validate($params, 'AccountCreate');
        if(true !== $result){
            return myerr($result);
        }
       $params['CreatUserId'] = $this->user_id;
        // 判断是否同步
        if(isset($params['IsSync']) && $params['IsSync'] == 1) {
            $params['EndFlag'] = 1;
        }

        // 查询公司信息
        $company = (new Company())->where('UserId', $params['CreatUserId'])->find();
        if(!empty($company)) {
            $params['CreateUserName'] = $company['UserName'];
        }
        // 将内容插入
        $res = (new AccountCreate())->addCreate($params);
        if ($res) {
            return myok('添加成功');
        } else {
            return myerr($res);
        }


    }
    // 生成批量编号
}
